package com.scc.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.scc.mapper.AdminOperationLogMapper;
import com.scc.pojo.AdminOperationLog;
import com.scc.pojo.PageBean;
import com.scc.service.AdminOperationLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class AdminOperationLogServiceImpl implements AdminOperationLogService {
    //注入mapper接口
    @Autowired
    private AdminOperationLogMapper adminOperationLogMapper;

    @Override
    public PageBean getAdminOperationLogs(Integer page, Integer pageSize, String username, Integer rights, LocalDateTime startTime, LocalDateTime endTime) {
        PageHelper.startPage(page, pageSize);
        //将rights转化为字符串
        String adminRights = null;
        if(rights == 0){
            adminRights="无权管理员";
        }else if(rights == 1){
            adminRights="有权管理员";
        }
        List<AdminOperationLog> adminOperationLogList = adminOperationLogMapper.getAdminOperationLogs(username,adminRights,startTime,endTime);
        PageInfo<AdminOperationLog> pageInfo = new PageInfo<>(adminOperationLogList);
        return new PageBean(pageInfo.getTotal(), pageInfo.getList());
    }
    //高级管理员对日志的删除操作
    @Override
    public void deleteAdminOperationLogs(List<Integer> ids) {
        //传入删除的id
        adminOperationLogMapper.deleteAdminOperationLogs(ids);
    }
}
